#include<bits/stdc++.h>
using namespace std;

const int N=2e5+5;

int t;
int n,ans;
int a[N];
int c[N];

inline int read(){
    int f=1,k=0;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        k=k*10+c-'0';
        c=getchar();
    }
    return f*k;
}

void A(int x){
    if(x==n+1){
        int lans=0;
        for(int i=2;i<=n;i++){
            for(int j=i-1;j>=1;j--){
                if(c[i]==c[j]){
                    if(a[i]==a[j]) lans+=a[j];
                    break;
                }
            }
        }
        ans=max(ans,lans);
        return;
    }
    for(int i=1;i<=2;i++){
        c[x]=i;
        A(x+1);
    }
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    t=read();
    while(t--){
        n=read();
        for(int i=1;i<=n;i++) a[i]=read();
        if(n<=15){
            ans=0;
            A(1);
            cout<<ans<<endl;
            continue;
        }
    }
    return 0;
}
